;(function(FormBase) {
    FormBase.Checkbox = FormBase.extend({
        constructor: function(singleId, mainContent, formConfig) {

            //不初始化监听事件
            this.inherit(singleId, mainContent, formConfig, true);

            //创建Checkbox具体表单
            var t, inputStr = "",
                dataArray = formConfig.dataArray;
            if (!dataArray || !dataArray.length) {
                //未配置数据
                console.error("no Checkbox data array,please check....");
            } else {
                for (var i = 0; i < dataArray.length; i++) {
                    t = dataArray[i];
                    inputStr += '<div class="' + formConfig.checkboxClass + 'Container">' +
                        '<input type="checkbox" class="' + formConfig.checkboxClass + '" name="' + formConfig.id + 'Checkbox"  value="' + t.value + '" readonly="readonly"><span>' + t.label + '</span></div>';
                }
                $(this.formEle).after(inputStr).addClass("hide");
            }
            this.initMouseListeners();
        },
        initMouseListeners: function() {
            var checkboxs = document.getElementsByName(this.formEleId + "Checkbox");
            for (var i = 0; i < checkboxs.length; i++) {
                if (document.all) { // IE
                    checkboxs[i].attachEvent("onclick", this.clickAction.bindAsEventListener(this));
                } else {
                    checkboxs[i].addEventListener("click", this.clickAction.bindAsEventListener(this), false);
                }
            }
        },
        clickAction: function(e) {
            var t2, checkboxs, valStr = "",
                tt = $(e.target || e.srcElement);
            t2 = $("#" + $(this.formEle).attr("id") + this.mainContent.errPostfix);
            if (this.clearErrorFocus && t2.length) t2.html("").addClass("hide");

            if (tt.hasClass("checked")) tt.removeClass("checked");
            else tt.addClass("checked");
            checkboxs = document.getElementsByName(this.formEleId + "Checkbox");
            for (var i = 0; i < checkboxs.length; i++) {
                if ($(checkboxs[i]).hasClass("checked")) valStr += $(checkboxs[i]).val() + ",";
            }
            if (valStr) {
                valStr = valStr.substring(0, valStr.length - 1);
                delete this.mainContent[this.mainContent.formId + "errForm"][this.formEleId];
            } else this.mainContent[this.mainContent.formId + "errForm"][this.formEleId] = {
                value: "",
                status: false,
                msg: this.emptyMsg
            };
            this.formEle.value = valStr;
        }
    });
})(window.FormBase = window.FormBase || {})
